

* This file uses the 2008-9 Panel Study, http://https://electionstudies.org/data-center/2008-2009-panel-study/
 
gen pid = .
replace pid = -3 if DER08W1 == 10
replace pid = -2 if DER08W1 == 11
replace pid = -1 if DER08W1 == 12
replace pid = 0 if DER08W1 == 13
replace pid = 1 if DER08W1 == 14
replace pid = 2 if DER08W1 == 15
replace pid = 3 if DER08W1 == 16

gen rep = 1 if pid > 0 & pid < .
replace rep = 0 if pid < 0

gen pidstrength1 = abs(pid) + 1

* Affective, parties
gen dem6 = . 
replace dem6 = 4 if W6E2 == 12 
replace dem6 = 1 if W6E4 == 10
replace dem6 = 2 if W6E4 == 11
replace dem6 = 3 if W6E4 == 12
replace dem6 = 5 if W6E3 == 12
replace dem6 = 6 if W6E3 == 11
replace dem6 = 7 if W6E3 == 10

gen rep6 = . 
replace rep6 = 4 if W6E5 == 12 
replace rep6 = 1 if W6E7 == 10
replace rep6 = 2 if W6E7 == 11
replace rep6 = 3 if W6E7 == 12
replace rep6 = 5 if W6E6 == 12
replace rep6 = 6 if W6E6 == 11
replace rep6 = 7 if W6E6 == 10

gen dem9 = . 
replace dem9 = 4 if W9E2 == 12 
replace dem9 = 1 if W9E4 == 10
replace dem9 = 2 if W9E4 == 11
replace dem9 = 3 if W9E4 == 12
replace dem9 = 5 if W9E3 == 12
replace dem9 = 6 if W9E3 == 11
replace dem9 = 7 if W9E3 == 10

gen rep9 = . 
replace rep9 = 4 if W9E5 == 12 
replace rep9 = 1 if W9E7 == 10
replace rep9 = 2 if W9E7 == 11
replace rep9 = 3 if W9E7 == 12
replace rep9 = 5 if W9E6 == 12
replace rep9 = 6 if W9E6 == 11
replace rep9 = 7 if W9E6 == 10


* Affective, candidates 
gen mccain6 = .
replace mccain6 = 4 if W6E14 == 12
replace mccain6 = 1 if W6E16 == 10
replace mccain6 = 2 if W6E16 == 11
replace mccain6 = 3 if W6E16 == 12
replace mccain6 = 5 if W6E15 == 12
replace mccain6 = 6 if W6E15 == 11
replace mccain6 = 7 if W6E15 == 10

gen mccain9 = .
replace mccain9 = 4 if W9E14 == 12
replace mccain9 = 1 if W9E16 == 10
replace mccain9 = 2 if W9E16 == 11
replace mccain9 = 3 if W9E16 == 12
replace mccain9 = 5 if W9E15 == 12
replace mccain9 = 6 if W9E15 == 11
replace mccain9 = 7 if W9E15 == 10

gen obama6 = .
replace obama6 = 4 if W6E38 == 12
replace obama6 = 1 if W6E40 == 10
replace obama6 = 2 if W6E40 == 11
replace obama6 = 3 if W6E40 == 12
replace obama6 = 5 if W6E39 == 12
replace obama6 = 6 if W6E39 == 11
replace obama6 = 7 if W6E39 == 10

gen obama9 = .
replace obama9 = 4 if W9E38 == 12
replace obama9 = 1 if W9E40 == 10
replace obama9 = 2 if W9E40 == 11
replace obama9 = 3 if W9E40 == 12
replace obama9 = 5 if W9E39 == 12
replace obama9 = 6 if W9E39 == 11
replace obama9 = 7 if W9E39 == 10

* Affective polarization scale
gen party6 = rep6-dem6 if pid > 0
replace party6 = dem6-rep6 if pid < 0

gen party9 = rep9-dem9 if pid > 0
replace party9 = dem9-rep9 if pid < 0

gen cand6 = mccain6-obama6 if pid > 0
replace cand6 = obama6-mccain6 if pid < 0

gen cand9 = mccain9-obama9 if pid > 0
replace cand9 = obama9-mccain9 if pid < 0

gen incand6 = mccain6 if pid > 0
replace incand6 = obama6 if pid < 0
gen incand9 = mccain9 if pid > 0
replace incand9 = obama9 if pid < 0
gen outcand6 = obama6 if pid > 0
replace outcand6 = mccain6 if pid < 0
gen outcand9 = obama9 if pid > 0
replace outcand9 = mccain9 if pid < 0


gen inparty6 = rep6 if pid > 0
replace inparty6 = dem6 if pid < 0
gen inparty9 = rep9 if pid > 0
replace inparty9 = dem9 if pid < 0
gen outparty6 = dem6 if pid > 0
replace outparty6 = rep6 if pid < 0
gen outparty9 = dem9 if pid > 0
replace outparty9 = rep9 if pid < 0


alpha party6 cand6, gen(affectpol6)
alpha party9 cand9, gen(affectpol9)

gen battleground = 0 
replace battle =1 if CDSTATE == 84  // Colorado, 
replace battle =1 if CDSTATE == 59  // Florida
replace battle =1 if CDSTATE == 34  // Michigan
replace battle =1 if CDSTATE == 43  // Missouri, 
replace battle =1 if CDSTATE == 88  // Nevada
replace battle =1 if CDSTATE == 11  // New Hampshire
replace battle =1 if CDSTATE == 85  // New Mexico
replace battle =1 if CDSTATE == 31  // Ohio
replace battle =1 if CDSTATE == 23  // Pennsylvania
replace battle =1 if CDSTATE == 54  // Virginia


mean cand6 cand9
mean party6 party9

mean cand6 cand9 , over(battleground)
ttest cand6=cand9 if battleground==0
ttest cand6=cand9 if battleground==1

mean party6 party9 , over(battleground)
ttest party6=party9 if battleground==0
ttest party6=party9 if battleground==1

mean outcand6 outcand9 incandidate6 incandidate9
ttest outcand6=outcand9 
ttest incandidate6=incandidate9 
mean outparty6 outparty9 inparty6 inparty9
ttest outparty6=outparty9 
ttest inparty6=inparty9 

